#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"

#define PLAY_CARD adventurer
#define PLAY_CARD_STR "adventurer"

int main() {
    int i; 
	int game;
	int num_cards_in_hand;
    int player_count;
    int seed;
    int k[10] = {gardens, mine, feast, great_hall, remodel, smithy, village, adventurer, council_room, baron};
    struct gameState G;
	
    int cardChange = 5;
    int cards_in_hand[5];
	
	int cards_hand_1;
	int cards_hand_2; 

	cards_in_hand[0] = adventurer; // put adventurer in hand
   		
    printf ("tesing card 'adventurer'\n");

	for(i=0;i<3000;i++){
		
		// randomize variables
		num_cards_in_hand = floor(Random() * 5) + 1;
		player_count = floor(Random() * 3) + 2;
		seed = floor(Random() * 200);
		
		// printf("num_cards_in_hand = %d, player_count = %d\n",num_cards_in_hand,player_count);
		memset(&G, 23, sizeof(struct gameState));   // clear the game state
	    game = initializeGame(player_count, k, seed, &G); // initialize a new game
			
		if(num_cards_in_hand == 1 && player_count == 2){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand); 
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 1 && player_count == 3){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand);
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 1 && player_count == 4){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand); 
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 2 && player_count == 2){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand); 
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 2 && player_count == 3){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand);
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 2 && player_count == 4){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand); 
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 3 && player_count == 2){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand); 
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 3 && player_count == 3){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand); 
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 3 && player_count == 4){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand); 
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 4 && player_count == 2){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand); 
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 4 && player_count == 3){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand);
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 4 && player_count == 4){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand); 
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 5 && player_count == 2){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand); 
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 5 && player_count == 3){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand);
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}
		
		if(num_cards_in_hand == 5 && player_count == 4){
			G.handCount[0] = num_cards_in_hand;                 // set the number of cards on hand
			memcpy(G.hand[0], cards_in_hand, sizeof(int) * num_cards_in_hand); 
			cards_hand_1 = G.handCount[0];
			game = playCard(0,0,0,0,&G); // play first card in hand
			cards_hand_2 = G.handCount[0];		
			assert(cards_hand_2 == num_cards_in_hand -1 + cardChange); // assert cards in hand is correct
			printf("assertion correct!\n");
		}	

	}
    
    printf("Testing on adventurer complete - good!\n\n");
        
    return 0;
}
